@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Event
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.DrawerPageBase<k8s.Models.V2HorizontalPodAutoscaler>
@if (HorizontalPodAutoscaler != null)
{
    <HorizontalPodAutoscalerAction Item="HorizontalPodAutoscaler" MenuMode="MenuMode.Horizontal"></HorizontalPodAutoscalerAction>
    <Divider Orientation="left" Style="font-weight:bold">@L["Metadata"]</Divider>
    <MetadataView Item="HorizontalPodAutoscaler.Metadata" ExplainFieldPrefix="horizontalPodAutoscaler"></MetadataView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Spec"]</Divider>
    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["MaxReplicas"] Item="@HorizontalPodAutoscaler.Spec.MaxReplicas"
                            ExplainField="horizontalPodAutoscaler.spec.maxReplicas">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["MinReplicas"] Item="@HorizontalPodAutoscaler.Spec.MinReplicas"
                            ExplainField="horizontalPodAutoscaler.spec.minReplicas">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["ScaleTargetRef"] ExplainField="horizontalPodAutoscaler.spec.scaleTargetRef">
            <RefView FullView="true" Ref="@TransferToRef()"></RefView>
        </PropertySimpleView>
    </HTable>
    @if (HorizontalPodAutoscaler.Spec.Behavior != null)
    {
        <Divider Orientation="left" Style="font-weight:bold">@L["Behavior"]</Divider>
        <HTable Bordered Column="1">
            <PropertySimpleView Title=@L["ScaleUp"] ExplainField="horizontalPodAutoscaler.spec.behavior.scaleUp">
                @if (HorizontalPodAutoscaler.Spec.Behavior.ScaleUp != null)
                {
                    <HPABehaviorView Behavior="@HorizontalPodAutoscaler.Spec.Behavior.ScaleUp"></HPABehaviorView>
                }
            </PropertySimpleView>
            <PropertySimpleView Title=@L["ScaleDown"] ExplainField="horizontalPodAutoscaler.spec.behavior.scaleDown">
                @if (HorizontalPodAutoscaler.Spec.Behavior.ScaleDown != null)
                {
                    <HPABehaviorView Behavior="@HorizontalPodAutoscaler.Spec.Behavior.ScaleDown"></HPABehaviorView>
                }
            </PropertySimpleView>
        </HTable>
    }

    <HPAMetricsView Hpa="@HorizontalPodAutoscaler"></HPAMetricsView>

    <Divider Orientation="left" Style="font-weight:bold">@L["Status"]</Divider>
    <HTable Bordered Column="1">
        <ConditionsView Conditions="@(HorizontalPodAutoscaler.Status.Conditions.Adapt<IList<V1Condition>>())" ExplainField="deployment.status.conditions"></ConditionsView>

        <PropertySimpleView Title=@L["CurrentReplicas"] Item="@HorizontalPodAutoscaler.Status.CurrentReplicas"
                            ExplainField="horizontalPodAutoscaler.status.currentReplicas">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["DesiredReplicas"] Item="@HorizontalPodAutoscaler.Status.DesiredReplicas"
                            ExplainField="horizontalPodAutoscaler.status.desiredReplicas">
        </PropertySimpleView>
        @if (HorizontalPodAutoscaler.Status.LastScaleTime != null)
        {
            <PropertySimpleView Title=@L["LastScaleTime"] ExplainField="horizontalPodAutoscaler.status.lastScaleTime">
                <AgeView Age="@HorizontalPodAutoscaler.Status.LastScaleTime"></AgeView>
                (@HorizontalPodAutoscaler.Status.LastScaleTime.GetValueOrDefault().ToLocalTime())
            </PropertySimpleView>
        }
        <PropertySimpleView Title=@L["ObservedGeneration"] Item="@HorizontalPodAutoscaler.Status.ObservedGeneration"
                            ExplainField="horizontalPodAutoscaler.status.observedGeneration">
        </PropertySimpleView>
    </HTable>
    <MiniEventListView Uid="@HorizontalPodAutoscaler.Metadata.Uid"></MiniEventListView>
}
